package Env;
import java.util.Arrays;
import java.util.Vector;



public class Environment {

	private final Graph graph;
	private Vector<Car>[] vertexes;
	private static boolean singleton=false;

	public Environment (Graph g) throws Exception{
		if (singleton)
			throw new Exception ("singleton already created");
		graph=g;
		vertexes=new Vector[graph.n+1];
		for (int i=0;i<=g.n;i++)
			vertexes[i]=new Vector<Car>();
		singleton=true;
	}

	public void addCar(int v, int speed, float f) throws Exception {
		vertexes[v].add(new Car(speed, f));
	}

	public float drive(int from,int to,Car car) throws Exception{
		System.out.println(car);
		vertexes[from].remove(car);
		vertexes[to].add(car);
		if (graph.isEdgeFlooded(from, to))
			return (graph.getEdgeCost(from, to)/(car.getSpeed()*car.getEff()));
		else
			return (graph.getEdgeCost(from, to)/(car.getSpeed()));

	}

	@Override
	public String toString() {
		return "Enviorment graph=\n" + graph + "\n\n\nvertexes=\n"
				+ Arrays.toString(vertexes);
	}
	
	public Graph getGraph(){
		return graph;
	}

	public Vector<Car> getCars(int vertex) {
		return vertexes[vertex];
	}









}
